package com.shuzijun.leetcode.editor.cn;
public class PeakIndexInAMountainArray{
    public static void main(String[] args) {
         Solution solution = new PeakIndexInAMountainArray().new Solution();
        
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int peakIndexInMountainArray(int[] arr) {
        int n = arr.length;
        int low = 0;
        int high = n-1;
        while (low <= high){
            int mid = (low+high)/2;
            if (mid == 0){
                low = mid+1;
            } else if (mid == n-1) {
                high = mid-1;
            } else if (arr[mid] > arr[mid-1] && arr[mid] > arr[mid+1]) {
                return mid;
            } else if (arr[mid] > arr[mid-1]) {
                low = mid+1;
            }else {
                high = mid-1;
            }
        }
        return -1;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}